package com.tdtxdcxm.ruralcommunity.slice;

import com.tdtxdcxm.ruralcommunity.ResourceTable;
import com.tdtxdcxm.ruralcommunity.appruntime.DataCenterControl;
import com.tdtxdcxm.ruralcommunity.myutils.MyTools;
import com.tdtxdcxm.ruralcommunity.providers.LCProviderForNormal;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

public class FollowAndFansListSlice extends AbilitySlice {
    private Button usercontent_backbut;
    private ListContainer usercontent_lc;


    private void initListContainer(ListContainer listContainer,String listContainerName,AbilitySlice slice){
        if(listContainer == null){
            return;
        }
        listContainer.setName(listContainerName);
        LCProviderForNormal lcProviderForNormal = null;
        switch (listContainerName) {
            case "followlistlc":
                lcProviderForNormal = new LCProviderForNormal(DataCenterControl.follow_listcontainer_list,this);
                break;
            case "fanslistlc":
                lcProviderForNormal = new LCProviderForNormal(DataCenterControl.fans_listcontainer_list,this);
                break;
            default:
                break;
        }

        if(lcProviderForNormal != null){
            listContainer.setItemProvider(lcProviderForNormal);
            DataCenterControl.followAndFanaListListContainerProvider = lcProviderForNormal;
        }

        listContainer.setItemLongClickedListener(new ListContainer.ItemLongClickedListener() {
            @Override
            public boolean onItemLongClicked(ListContainer listContainer, Component component, int i, long l) {
                DirectionalLayout directionalLayout= ((DirectionalLayout)component);
                Text text = (Text)directionalLayout.getComponentAt(0);

                if(listContainer.getName().equals("followlistlc")){
                    MyTools.commonDialogRemoveShow("取消关注提示","是否取消关注？",component,i,FollowAndFansListSlice.this,"unfollow");
                }
                return true;
            }
        });
    }

    private void initPLSComponents(){
        usercontent_backbut = (Button) findComponentById(ResourceTable.Id_usercontent_backbut);
        usercontent_lc = (ListContainer) findComponentById(ResourceTable.Id_usercontent_lc);

        usercontent_backbut.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                DataCenterControl.follow_listcontainer_list.clear();
                DataCenterControl.fans_listcontainer_list.clear();
                terminate();
            }
        });
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_usercontent_item_listcontainer);
        initPLSComponents();
        String type = intent.getStringParam("type");
        switch (type) {
            case "followlist":
                initListContainer(usercontent_lc,"followlistlc",this);
                MyTools.DownDataFollowAndFanslistInfo(this,DataCenterControl.userName,"followlist");
                break;
            case "fanslist":
                initListContainer(usercontent_lc,"fanslistlc",this);
                MyTools.DownDataFollowAndFanslistInfo(this,DataCenterControl.userName,"fanslist");
                break;
            default:
                break;
        }
    }

    @Override
    protected void onActive() {
        super.onActive();
    }

    @Override
    protected void onInactive() {
        super.onInactive();
    }

    @Override
    protected void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    protected void onBackground() {
        super.onBackground();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }
}
